package com.chao.deeply.future;

import lombok.SneakyThrows;

import java.util.concurrent.*;

/**
 * @author : Rookie
 * @description :
 * @date : 2023/5/8
 */
public class FutureTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ExecutorService executorService = Executors.newCachedThreadPool();

        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                TimeUnit.SECONDS.sleep(3);
                return "call方式，返回字符串！";
            }
        };

        Runnable runnable = new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                TimeUnit.SECONDS.sleep(3);
                System.out.println("执行了run方法！");
            }
        };

        Future<String> future = executorService.submit(callable);
        Future<?> future1 = executorService.submit(runnable);
        System.out.println(future.get());
        System.out.println(future1.get());
    }
}
